function [lw_grid, P_eta, cdf_u, cdf_c] = wageproc_fn(stoch_earn, m_eta, n_eta)

% This function creates the grid of the stochastic process of wages and the
% transition probabilities. 

sigma_xi=stoch_earn(3)^0.5; 
if stoch_earn(1)< 1
    meanlw=stoch_earn(2)/(1-stoch_earn(1)); 
    sdlw=sigma_xi/((1-stoch_earn(1)^2)^(0.5));
else
    meanlw=stoch_earn(2); 
    sdlw=sigma_xi;
end

lw_grid(1)=meanlw - m_eta*sdlw; 
lw_grid(n_eta)=meanlw + m_eta*sdlw; 

dlw=(lw_grid(n_eta)-lw_grid(1))/(n_eta-1); 

for i=2:n_eta-1;
    lw_grid(i)=lw_grid(i-1) + dlw;
end

P_eta=zeros(n_eta,n_eta);

for i=1:n_eta 
   P_eta(i,1)=normcdf((lw_grid(1)+0.5*dlw-stoch_earn(1)*lw_grid(i)-stoch_earn(2))/sigma_xi); % Note! "-c"
end

for i=1:n_eta 
    P_eta(i,n_eta)=1-normcdf((lw_grid(n_eta)-0.5*dlw-stoch_earn(1)*lw_grid(i)-stoch_earn(2))/sigma_xi);  
end

for i=1:n_eta 
    for j=2:n_eta-1
        P_eta(i,j)=normcdf((lw_grid(j)+0.5*dlw-stoch_earn(1)*lw_grid(i)-stoch_earn(2))/sigma_xi) -normcdf((lw_grid(j)-0.5*dlw-stoch_earn(1)*lw_grid(i)-stoch_earn(2))/sigma_xi);
    end
end

cdf_u=zeros(1,n_eta);

cdf_u(1,n_eta)=1; 

for i=1:n_eta-1 
cdf_u(1,i)=normcdf((lw_grid(i)-0.5*dlw-stoch_earn(2))/sigma_xi); 
end

cdf_c=zeros(n_eta,n_eta); 

for i=1:n_eta 
    pastcdf=0; 
    for j=1:n_eta 
        currentcdf=pastcdf + P_eta(i,j);
        cdf_c(i,j)=currentcdf; 
        pastcdf=currentcdf;
    end
end
end

